package com.isoftstone.project.echars;

import com.isoftstone.framework.controller.BaseController;
import com.isoftstone.framework.domain.Tidings;
import com.isoftstone.project.buttjoint.domain.MonitorTest;
import com.isoftstone.project.buttjoint.mapper.MonitorTestMapper;
import com.isoftstone.project.buttjoint.service.IMonitorTestService;
import com.isoftstone.project.echars.domain.Series;
import com.isoftstone.project.facilities.management.domain.FacilitiesManagement;
import com.isoftstone.project.monitor.floor.domain.MonitorFloor;
import com.isoftstone.project.monitor.floor.mapper.MonitorFloorMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@Slf4j
@RequestMapping("/echars")
public class EcharsController extends BaseController {
    @Autowired
    MonitorTestMapper monitorTestMapper;
    @Autowired
    MonitorFloorMapper monitorFloorMapper;

    /**
     * 一周内的折线图(具体到分站下的传感器，根据分站传感器查询)
     * stationId 分站id
     * autoId    传感器id
     */
    @RequestMapping("/getzxtEchars")
    @ResponseBody
    public Object getzxtEchars(String stationId,String autoId)  {
        List<Series> serieslist=new ArrayList<>();
        Tidings<HashMap> tidings = new Tidings<>();
        HashMap map=new HashMap();
        Map<String,String> data = new HashMap<String,String>();
        Series series=new Series();
        series.setName("一周地下数据");
        series.setType("line");
        //获取当前时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        List<MonitorTest>   monitorTestList=monitorTestMapper.getweekmonitor(stationId,autoId);
        //根据用户编号跟产品编号查询
        List namelist=new ArrayList();
        List<String> daylist=new ArrayList<String>();
        if(!monitorTestList.isEmpty()){
            for (MonitorTest monitorTest : monitorTestList) {
                namelist.add(monitorTest.getWorkdate());
                if(monitorTest.getV()!=null){
                    daylist.add(monitorTest.getV());
                }else {
                    daylist.add("0");
                }
            }
        }

        series.setData(daylist);
        serieslist.add(series);
        map.put("shuzu1",serieslist);
        map.put("shuzu2",namelist);
        tidings.setT(map);
        return tidings;
    }
    /**
     * 饼图的实时数据(具体到分站下的传感器，根据分站查询)
     * stationId 分站id
     */
    @RequestMapping("/getbtEchars")
    @ResponseBody
    public Object getbtEchars(String stationId)  {

        List<MonitorTest> monitorTestList=monitorTestMapper.selectBtEchars(stationId);

        return Tidings.success(monitorTestList);
    }
    /**
     * 井上异常站点数据
     *
     */
    @RequestMapping("/getyczdEchars")
    @ResponseBody
    public Object getyczdEchars()  {
        List<MonitorFloor> monitorTestList=monitorFloorMapper.selectyczdEchars();
        String account= String.valueOf(monitorTestList.size());//总站点数
        List<MonitorFloor> errormonitorTestList=monitorFloorMapper.selecterroryczdEchars();
        String erroraccount= String.valueOf(errormonitorTestList.size()); //异常站点
        List<MonitorFloor> errorweekmonitorTestList=monitorFloorMapper.selecterrweekoryczdEchars();
        String errorweekaccount= String.valueOf(errorweekmonitorTestList.size()); //一周异常站点
        Map<String,String> map = new HashMap<String,String>();
        map.put("account",account);//总站点数
        map.put("erroraccount",erroraccount);//异常站点
        map.put("errorweekaccount",errorweekaccount);//一周异常站点
        return Tidings.success(map);
    }
}
